package inteceptor;

import java.lang.reflect.Modifier;
import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyInterceptor {
	
	@Pointcut("execution (* service..*.*(..))")
	private void serviceMethod() {}
	
	@Pointcut("execution (* dao..*.*(..))")
	private void daoMethod() {}
	
	@Pointcut("execution (* action..*.*(..))")
	private void actionMethod() {}
	
	@Before("daoMethod()|| serviceMethod() || actionMethod()")
	public void doAccessCheck(JoinPoint pjp) {
		System.out.println("进入类:" +pjp.getTarget().getClass().getName()
	            + "的方法"+Modifier.toString(pjp.getSignature().getModifiers())
	            + " " +((MethodSignature) pjp.getSignature()).getReturnType().getSimpleName()
	            + " " + pjp.getSignature().getName()
	            + "(" + Arrays.toString(pjp.getArgs()) + ")" );
	}

//	@After("anyMethod()")
	public void doAfter() {
	     System.out.println("����֪ͨ");
	}

//	@AfterReturning(pointcut="anyMethod()",returning="result")
	public void doAfterReturning(String result) {
	     System.out.println("����֪ͨ:"+ result);
	}
	
//	@AfterThrowing(pointcut="anyMethod()",throwing="e")
	public void doAfterThrowing(Exception e) {
	     System.out.println("����֪ͨ:"+ e);
	}

//	@Around("anyMethod()")
	public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
		//if(){//�ж��û��Ƿ���Ȩ��
			System.out.println("���뷽��");
			System.out.println("����" +pjp.getTarget().getClass().getName()
					            + "��ķ���"+java.lang.reflect.Modifier.toString(pjp.getSignature().getModifiers())
					            + "***" 
					            + "***" + pjp.getSignature().getName()
					            + "(" + Arrays.toString(pjp.getArgs()) + ")" );
			Object result = pjp.proceed();
			System.out.println("�˳��");
		//}
		return result;
	}
	


}
